//
//  RW_InputCollectionViewCell.m
//  SleepApp
//
//  Created by chuangqi on 2021/3/30.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_InputCollectionViewCell.h"
@interface RW_InputCollectionViewCell (){
    RW_InputCollectionViewCellModel *_model;
}
@property (nonatomic,strong) UILabel *wlclass_title_label;
@property (nonatomic,strong) UITextField *wlclass_text_field;
@end
@implementation RW_InputCollectionViewCell

//    Cell_Input_Type_Default,//默认
//    Cell_Input_Type_Account,//账号
//    Cell_Input_Type_PassWord,//密码
//    Cell_Input_Type_Verify_PassWord,//确认密码
//    Cell_Input_Type_NickName,//昵称

-(void)bind_row_data:(WLBaseCollectionViewLayerRow *)sender{
    if ([sender.data isKindOfClass:RW_InputCollectionViewCellModel.class]){
        _model = sender.data;
        
        self.wlclass_text_field.placeholder = _model.placeholder_string;
        self.wlclass_text_field.text = _model.default_input_text_string;
        
        self.wlclass_title_label.text = _model.title_string;
        
        self.wlclass_text_field.secureTextEntry = _model.secureTextEntry;

        switch (_model.input_type) {
            case Cell_Input_Type_NickName:
                self.wlclass_text_field.keyboardType = UIKeyboardTypeDefault;
                break;
            default:
                self.wlclass_text_field.keyboardType = UIKeyboardTypeASCIICapable;
                break;
        }
        
    }
}
-(void)bind_delegate:(id)sender{
    
}
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = UIColor.whiteColor;
        [self addSubview:self.wlclass_text_field];
        [self addSubview:self.wlclass_title_label];
        [self.wlclass_title_label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.mas_equalTo(self);
            make.left.mas_equalTo(self).mas_offset(15);
            make.width.mas_offset(70);
        }];
        [self.wlclass_text_field mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.mas_equalTo(self);
            make.left.mas_equalTo(self.wlclass_title_label.mas_right).mas_offset(15);
        }];
    }
    return self;
}
#pragma mark -- 代理
-(void)changeInputText:(NSString *)text{
    _model.input_text_string = text;
}


#pragma mark -- 懒加载
-(UITextField *)wlclass_text_field{
    if (!_wlclass_text_field){
        _wlclass_text_field = [[UITextField alloc]init];
        _wlclass_text_field.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
        _wlclass_text_field.autocapitalizationType = UITextAutocapitalizationTypeNone;
        __WEAK_SELF_YLSLIDE
        [_wlclass_text_field.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
            [weakSelf changeInputText:x];
        }];
    }
    return _wlclass_text_field;
}
-(UILabel *)wlclass_title_label{
    if (!_wlclass_title_label){
        _wlclass_title_label = [[UILabel alloc]init];
        _wlclass_title_label.font = [UIFont systemFontOfSize:15 weight:UIFontWeightRegular];
//        _wlclass_title_label.textAlignment = NSTextAlignmentCenter;
    }
    return _wlclass_title_label;
}
@end


@implementation RW_InputCollectionViewCellModel

@end
